//index.js
var app = getApp();
var that;
var chatListData = [];
Page({
  data: {
    title: '您已加入小胖，现在可以开始聊天了。',
    left: "http://oky0avxwu.bkt.clouddn.com/left.png",
    right: "http://oky0avxwu.bkt.clouddn.com/right.png",
    voice: "http://oky0avxwu.bkt.clouddn.com/voice.png",
    xiaopang: 'http://oky0avxwu.bkt.clouddn.com/xiaopang.png',
    chatList: [],
    pang: [
            {
                xiaopang: "小胖是格悦科技的美食AI对话机器人，您可以和我聊天或输入午饭吃啥回答小胖的问题哦。",
            },
            {
                xiaopang: "“输入午饭吃啥可以进入问答模式”或“随便和小胖聊天哦”",
            },
    ],
    msg1: "",
    msg2: "111",
    userInfo: {},
    inputDetail: '',
  },
  inputDesc: function(e) {
      var word = e.detail.value;
      this.setData({
          msg1: word,
      });
      console.log(this.data.msg1);
  },
  sendMsg:function() {
    var that = this;
    var talk;
    var msg1 = this.data.msg1;
    var msg2 = this.data.msg2;
    var chatList = this.data.chatList;
    wx.request({
        url: 'https://xiaopang.demo.yanxishe.cc/h5/tuling/index?id=123&nickname=%E5%BC%A0%E4%B8%89&content=12',
        data: {"id":203020,"content":msg1,"nickname":"io","sex":"男"},
        method: 'GET', 
        header: {"Content-Type":"json"},
        success: function(res) {
            that.setData({
                inputDetail: '',
            });
            console.log(res.data.tip);
            msg2 = res.data.tip;
            var talk = { text: msg1, text1: msg2,'time': new Date().getTime(), };
            chatListData.push(talk);
            that.setData({
                chatList: chatListData,
            });
            console.log(chatList);
        },
        fail: function() {
          console.log("小胖不在家！")
        },
        complete: function() {
          console.log("快来和小胖聊天吧！")
        }
    });
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: ''
    })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})
